package com.zbkj.crmeb.member.controller;


import com.common.CommonPage;
import com.crmeb.core.common.CommonResult;
import com.common.PageParamRequest;
import com.zbkj.crmeb.member.model.MerchantMemberBenefits;
import com.zbkj.crmeb.member.model.StoreProductLabel;
import com.zbkj.crmeb.member.request.StoreProductLabelRequest;
import com.zbkj.crmeb.member.service.IStoreProductLabelService;
import com.zbkj.crmeb.member.vo.MerchantMemberBenefitsVO;
import com.zbkj.crmeb.merchant.admin.controller.AdminBaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 商品标签表 前端控制器
 * </p>
 *
 * @author xx
 * @since 2022-05-31
 */
@RestController
@RequestMapping("api/admin/mer/product/label")
@Api(tags = "商户商品标签管理")
public class StoreProductLabelController extends AdminBaseController {
    @Autowired
    private IStoreProductLabelService storeProductLabelService;

    @ApiOperation(value = "商户标签查询")
    @RequestMapping(value = "/getLabel", method = RequestMethod.POST)
    public CommonResult<CommonPage<StoreProductLabel>> getMemberBenefits(@RequestBody StoreProductLabelRequest request, HttpServletRequest servletRequest){
        request.setMerId(getMerId(servletRequest));
        return CommonResult.success(storeProductLabelService.getLabel(request));
    }

    @ApiOperation(value = "商户标签新增或编辑")
    @RequestMapping(value = "/addOrUpdLabel", method = RequestMethod.POST)
    public CommonResult<Object> addOrUpdLabel(@RequestBody StoreProductLabel storeProductLabel, HttpServletRequest servletRequest){
        storeProductLabel.setMerId(getMerId(servletRequest));
        return storeProductLabelService.addOrUpdLabel(storeProductLabel) ? CommonResult.success() : CommonResult.failed();
    }

    @ApiOperation(value = "商户标签删除")
    @RequestMapping(value = "/delLabel", method = RequestMethod.GET)
    public CommonResult<Object> delLabel(@RequestParam Integer id, HttpServletRequest servletRequest){
        return storeProductLabelService.delLabel(id) ? CommonResult.success() : CommonResult.failed();
    }

    @ApiOperation(value = "商品标签添加")
    @RequestMapping(value = "/addProductLabel", method = RequestMethod.POST)
    public CommonResult<Object> addProductLabel(@RequestBody StoreProductLabelRequest request, HttpServletRequest servletRequest){
        if (StringUtils.isEmpty(request.getLabelId())){
            return CommonResult.failed("商品标签不能为空");
        }
        if (StringUtils.isEmpty(request.getLabelDisplayType())){
            return CommonResult.failed("标签展示类型不能为空");
        }
        if (CollectionUtils.isEmpty(request.getProductIdList())){
            return CommonResult.failed("商品不能为空");
        }
        return storeProductLabelService.addProductLabel(request) ? CommonResult.success() : CommonResult.failed();
    }

    @ApiOperation(value = "商品标签清除")
    @RequestMapping(value = "/clearProductLabel", method = RequestMethod.POST)
    public CommonResult<Object> clearProductLabel(@RequestBody StoreProductLabelRequest request, HttpServletRequest servletRequest){
        if (StringUtils.isEmpty(request.getClearType())){
            return CommonResult.failed("清除类型不能为空");
        }
        return storeProductLabelService.clearProductLabel(request) ? CommonResult.success() : CommonResult.failed();
    }

}

